package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLeveService;
import com.zzyl.vo.NursingLevelV0;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class NursingLeveServiceImpl implements NursingLeveService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    @Override
    public List<NursingLevelV0> getAllLevel() {
        List<NursingLevelV0> list = nursingLevelMapper.getAllLevel();
        return list;
    }

    @Override
    public void addLevel(NursingLevelDto dto) {
        NursingLevel nursingLevel = new NursingLevel();
        BeanUtils.copyProperties(dto,nursingLevel);
        nursingLevelMapper.addLevel(nursingLevel);
    }

    @Override
    public ResponseResult getByPage(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingLevelV0> page = nursingLevelMapper.getByPage(name,status);
        NursingLevelV0 nursingLevelV0 = new NursingLevelV0();
        PageResponse of = PageResponse.of(page, nursingLevelV0.getClass());
        return ResponseResult.success(of);
    }

    @Override
    public NursingLevelV0 getById(Integer id) {
        NursingLevelV0 nursingLevelV0 = nursingLevelMapper.getById(id);
        return nursingLevelV0;
    }

    @Override
    public void update(NursingLevelDto dto) {
        nursingLevelMapper.update(dto);
    }

    @Override
    public void dalete(Integer id) {
        nursingLevelMapper.delete(id);
    }

    @Override
    public void updateStatus(Integer id, Integer status) {
        nursingLevelMapper.updateStatus(id,status);
    }
}
